package com.zx.controller.dj;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zx.service.dj.RoleManageService;

/**
 * 
 * @author yt
 *
 */
@Controller
@RequestMapping("store")
public class RoleManageController {

	@Autowired
	RoleManageService RoleManageService;

	@RequestMapping("toAddRole")
	public String toAddRole(Model model) {
		return "dj/AddRole";
	}

	@RequestMapping("toSetPassword")
	public String toSetPassword(Model model) {
		return "dj/SetPassword";
	}

	/**
	 * 添加角色
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping("addRole")
	public String addRole(Model mod, String name, String password, String role, String function) {
		try {
			RoleManageService.insRole(name, password, role, function);
			mod.addAttribute("result", "1");
		} catch (Exception e) {
			mod.addAttribute("result", "0");
			e.printStackTrace();
		}

		return "dj/AddRole";
	}

	/**
	 * 密码修改
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping("setPassword")
	public String setPassword(Model mod, String name, String password, String newpassword,String againpassword ) {
		try {
			int x = RoleManageService.uptPassword(name, password, newpassword, againpassword);
			mod.addAttribute("result", "1");
			mod.addAttribute("x", x);
		} catch (Exception e) {
			mod.addAttribute("result", "0");
			e.printStackTrace();
		}

		return "dj/SetPassword";
	}
}